<template>
  <el-tree
    :props="props"
    :load="loadNode"
    @node-click='getName'
    lazy
  >
  </el-tree>
</template>

<script>
export default {
  name:'ProductTree',
  data(){
      return{
          props:{
              label: 'name',
              children: '',
          }
      }
  },
  methods:{
      getName(data){
          this.$emit('getleimu',data)
      },
      loadNode(node, resolve) {
        if (node.level === 0) {
          this.$api.getSelectCategory(1)
          .then(data=>{
              return resolve(data.data)
          })
        }else{
            this.$api.getSelectCategory(node.data.cid)
            .then(data=>{
                return resolve(data.data)
            })
            .catch(error=>{ // eslint-disable-line
                return resolve([])
            })
        }
        
      }
  }
}
</script>

<style>

</style>